<?php

namespace application\Module;

use library\Core\Db\CDbCriteria;
use application\Model\ProductImageModel;
use application\Comm\Func;

class ProductImage
{

    /**
     * @param $pid
     * @param array $select
     * @return array
     * 根据位置获取广告
     */
    public function getList($pid, $select = ['id', 'name', 'description', 'src'])
    {
        $criteria = new CDbCriteria();
        $criteria->select($select);
        $criteria->addEqCondition('product_id', $pid);
        $criteria->addEqCondition('is_del', 0);
        $criteria->addEqCondition('status', 1);
        $criteria->addOrderDesc('orderby');
        $imageModel = new ProductImageModel();
        $data = $imageModel->getListForArray($criteria);
        if(!empty($data)){
            foreach($data as $k => $v){
                $data[$k]['src'] = Func::imgUrl($v['src']);
                $data[$k]['src_data'] = $v['src'];
            }
        }
        return $data;
    }

}
